home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / COSEmulator / COSEmulator- SRC / src / MacOSEvents.cpp < prev    next >
Encoding:
Text File  |  1998-06-21  |  4.5 KB  |  223 lines  |  [TEXT/CWIE]

  1. //===================================================================
  2. //=======================  Headers        =============================
  3. #include "MacOSEvents.h"
  4. #include "GameTypes.h"
  5. #include "Screen.h"
  6. #include "MenuBar.h"
  7. #include "ApplicationHandler.h"
  8.  
  9. #include <string.h>
  10. //===================================================================
  11. //=======================  Globals        =============================
  12.  
  13. RgnHandle            rgn;
  14. point                last;    // last location of mouse
  15.  
  16. //===================================================================
  17. //=======================  #define        =============================
  18.  
  19.  
  20. //===================================================================
  21. //=======================  Function Prototypes    =====================
  22.  
  23. void    Handle_Key( char key );
  24. void    HandleMouseClick( Boolean down , point where );
  25. void    HandleMouseMove( point where );
  26.  
  27.  
  28.  
  29. void    InitEvents( void )
  30. {
  31.     rgn = NewRgn();
  32.     SetRectRgn( rgn , 0 , 0 , 1024, 768 );
  33.     
  34.     last.x = last.y = 0;
  35. }
  36.  
  37.  
  38. /*----------------------------------------------------------------------------\
  39.  
  40.     HandleMouseClick
  41.  
  42. \----------------------------------------------------------------------------*/
  43.  
  44. void    HandleMouseClick( Boolean down , point where )
  45. {
  46.     if( down )
  47.     {
  48.         if( !menuBar.HandleMouseClick( down , where ) )
  49.         {
  50.             AH.HandleMouseClick( down , where );
  51.         }
  52.     }
  53.     else
  54.     {
  55.         AH.HandleMouseClick( down , where );
  56.         menuBar.HandleMouseClick( down , where );
  57.     }
  58. }
  59.  
  60. /*----------------------------------------------------------------------------\
  61.  
  62.     HandleMouseMove
  63.  
  64. \----------------------------------------------------------------------------*/
  65.  
  66. void    HandleMouseMove( point where )
  67. {
  68.     AH.HandleMouseMove( where );
  69.     menuBar.HandleMouseMove( where );
  70. }
  71.  
  72. /*----------------------------------------------------------------------------\
  73.  
  74.     HandleInterface
  75.     
  76.     this is where most of the interface is handled - MAcOS
  77.  
  78. \----------------------------------------------------------------------------*/
  79.  
  80. void    HandleInterface( void )
  81. {
  82. WindowPtr    whichWindow;
  83. EventRecord    theEvent;
  84. long        whichPart;
  85. char        theKey = 0;
  86. Point        diskInitPt = {40,40};
  87. static        next = 0;
  88.  
  89.  
  90.  
  91.     WaitNextEvent(everyEvent, &theEvent, 0L, rgn );
  92.  
  93.         Point mouse;
  94.                 
  95.         GetMouse( &mouse );
  96.         
  97.         if(( mouse.h != last.x || mouse.v != last.y ) && 
  98.             ( mouse.h > 0 && mouse.v > 0 ) )
  99.         {
  100.             last.x = mouse.h;
  101.             last.y = mouse.v;
  102.             
  103.             HandleMouseMove( last );
  104.         }
  105.  
  106.         switch ( theEvent.what )
  107.         {
  108.             case mouseDown:
  109.     
  110.                 whichPart = FindWindow(theEvent.where, &whichWindow);
  111.                 switch ( whichPart )
  112.                 {
  113.                     case inMenuBar:
  114.                         whichPart = MenuSelect( theEvent.where );
  115.                         break;        
  116.                                         
  117.                     case inSysWindow:
  118.                         SystemClick(&theEvent, whichWindow);
  119.                         break;
  120.                         
  121.                     case inGoAway:
  122.  
  123.                         break;
  124.                         
  125.                     case inDrag:
  126.                     break;
  127.                     
  128.                     case inGrow: 
  129.  
  130.                         break;
  131.                         
  132.                     case inContent:
  133.                         
  134.                         point    pt;
  135.                         GlobalToLocal( &theEvent.where );
  136.                         pt.x = theEvent.where.h;
  137.                         pt.y = theEvent.where.v;
  138.                         
  139.                         HandleMouseClick( true , pt );
  140.                     break;
  141.                 }
  142.                 break;
  143.             
  144.             case mouseUp:
  145.                 point    pt;
  146.                 GlobalToLocal( &theEvent.where );
  147.                 pt.x = theEvent.where.h;
  148.                 pt.y = theEvent.where.v;
  149.                 
  150.                 HandleMouseClick( false , pt );
  151.             break;        
  152.                 
  153.             case keyDown:
  154.             case autoKey:
  155.                 theKey = (char)(theEvent.message & charCodeMask);
  156.         //        if ( ( (theEvent.modifiers & cmdKey) != 0) )
  157.         //            Handle_Menu_Choice(MenuKey(theKey));
  158.         //        else
  159.                     Handle_Key( theKey );
  160.                     
  161.                 break;
  162.  
  163.             case updateEvt:                
  164.                     BeginUpdate( (WindowPtr)theEvent.message );
  165.                         screen.DrawAll();
  166.                     EndUpdate( (WindowPtr)theEvent.message );
  167.                     
  168.                 break;
  169.                 
  170.             case activateEvt:
  171.                 break;
  172.  
  173.             case osEvt:
  174.                 switch((theEvent.message >> 24) & 0x000000FF)
  175.                     {
  176.                     case suspendResumeMessage:
  177.                     /*    if( (theEvent.message & resumeFlag) )
  178.                             background = false; // in foreground
  179.                         else
  180.                             background = true; //in background */
  181.                         break;
  182.                     
  183.                     case mouseMovedMessage:
  184.                         point    pt;
  185.         
  186.                         GlobalToLocal( &theEvent.where );
  187.                         pt.x = theEvent.where.h;
  188.                         pt.y = theEvent.where.v;
  189.                         
  190.                     break;
  191.                     
  192.                     default:
  193.  
  194.                     break;
  195.                     } 
  196.  
  197.                 break;                
  198.                     
  199.             case diskEvt:
  200. //Handle bad disk insertions
  201.                 if (HiWord(theEvent.message) != noErr)
  202.                 {
  203.                     DILoad();
  204.                     DIBadMount(diskInitPt, theEvent.message);
  205.                     DIUnload();
  206.                 }
  207.                 break;
  208.                 
  209.             default: 
  210.             break;
  211.         }; //case
  212. }
  213.  
  214. /*----------------------------------------------------------------------------\
  215.  
  216.     Handle_File_Choice
  217.  
  218. \----------------------------------------------------------------------------*/
  219.  
  220. void    Handle_Key( char key )
  221. {
  222.     //ExitToShell();
  223. }